home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------------
- #
- # Apple Macintosh Developer Technical Support
- #
- # Exception handling for MPW Pascal, MacApp and MPW C
- #
- # UFailure (aka Signals) - “Exceptional code, with a few exceptions.”
- #
- # CTestSignal.c - Test tool for C access to enhanced UFailure
- #
- # Copyright © 1985-1988 Apple Computer, Inc.
- # All rights reserved.
- #
- # Versions: 1.00 11/88
- # 1.01 06/92
- #
- # Components: CTestSignal.c November 1, 1988
- # CTestSignal.make November 1, 1988
- # PTestSignal.p November 1, 1988
- # PTestSignal.make November 1, 1988
- # UFailure.p November 1, 1988
- # UFailure.h November 1, 1988
- # UFailure.incl.p November 1, 1988
- # UFailure.a November 1, 1988
- #
- # UFailure (or Signals) is a set of exception handling routines suitable for
- # use with MacApp, MPW C, and MPW Pascal. It is a jazzed-up version of the MacApp
- # UFailure unit. There is a set of C interfaces to it as well.
- #
- ------------------------------------------------------------------------------*/
-
- #include <Types.h>
- #include <stdio.h>
- #include <Errors.h>
- #include <UFailure.h> /* C interfaces to UFailure stuff */
-
-
- FailInfo fi;
-
-
- pascal void Handler(short code, long message)
- {
- fprintf(stdout, "Handler() from Never(); message= %d, code= %d\n", message, code);
- /* this will do an implicit Failure() when it exits */
- }
-
-
- void Never()
- {
- short code;
-
- CatchCFailures(&fi, Handler); /* any caught by this one go to Handler */
-
- if (code = CatchSignal()) { /* if we’re getting a signal then… */
- fprintf(stdout, "Never() shouldn’t get here; code= %d\n", code);
- return;
- }
-
- FreeSignal(); /* “pop” the last Catchxxx */
-
- SignalMessage(7, 77777);
- }
-
-
- void Failer()
- {
- if (!CatchSignal())
- Never(); /* call Never; if a signal comes, fall through */
-
- Failure(69, 0); /* fail no matter what */
- }
-
-
- long Value()
- {
- short code;
-
- if (code = CatchSignal()) {
- fprintf(stdout, "Shouldn’t be here in Value(); code= %d\n", code);
- return code;
- }
-
- /* when this does its return the CatchSignal above will be automatically popped */
- if (code = CatchSignal())
- return code;
-
- Failer();
- }
-
-
- main()
- {
- short code;
- volatile long registerLong = 0;
-
- InitUFailure();
-
- if (code = CatchSignal()) {
- fprintf(stdout, "Signal caught in main(); code = %d, registerLong = %d\n",
- code, registerLong);
- return 0;
- }
-
- registerLong = 0xffff;
-
- Signal(Value());
- }
-